package bar.dark.lee.insert;

import android.app.Activity;
import android.app.LocalActivityManager;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TabHost;
import bar.dark.lee.BDConstents;
import bar.dark.lee.R;
import bar.dark.lee.SuperTabActivity;
import bar.dark.lee.cashdrawing.InsertMyBankActivity;
import bar.dark.lee.common.BDUtil;
import bar.dark.lee.setting.TipInfoActivity;
import bar.dark.lee.setting.TipsActivity;

public class InsertTabActivity extends SuperTabActivity
{
	private TabHost tabHost;
	
	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.tab_activity);
		setTitle("가계부 입력");
		
		tabHost = (TabHost) findViewById(R.id.tabHost);
		
		LocalActivityManager manager = getLocalActivityManager();
		tabHost.setup(manager);
		
		Intent intent1 = new Intent(this, InsertOutActivity.class);
		
		Intent intent2 = new Intent(this, InsertInActivity.class);
		
		Intent intent3 = new Intent(this, InsertPostActivity.class);
		
		LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
				0, LayoutParams.FILL_PARENT);
		params.weight = 1;
		
		tabHost.addTab(tabHost.newTabSpec("지출")
				.setIndicator(BDUtil.getTextView(this, "지출"))
				.setContent(intent1));
		tabHost.getTabWidget().getChildAt(0).setBackgroundResource(R.drawable.btn_set_tab);
		tabHost.getTabWidget().getChildAt(0).setLayoutParams(params);
		
		tabHost.addTab(tabHost.newTabSpec("수입")
				.setIndicator(BDUtil.getTextView(this, "수입"))
				.setContent(intent2));
		tabHost.getTabWidget().getChildAt(1).setBackgroundResource(R.drawable.btn_set_tab);
		tabHost.getTabWidget().getChildAt(1).setLayoutParams(params);
		
		tabHost.addTab(tabHost.newTabSpec("카드대금결제")
				.setIndicator(BDUtil.getTextView(this, "카드대금결제"))
				.setContent(intent3));
		tabHost.getTabWidget().getChildAt(2).setBackgroundResource(R.drawable.btn_set_tab);
		tabHost.getTabWidget().getChildAt(2).setLayoutParams(params);
		
		tabHost.addTab(tabHost.newTabSpec("")
				.setIndicator(new LinearLayout(this))
				.setContent(new Intent()));
		tabHost.getTabWidget().getChildAt(3).setVisibility(View.GONE);
		tabHost.getTabWidget().getChildAt(3).setLayoutParams(params);
		
		SharedPreferences pref = getSharedPreferences("pref", Activity.MODE_PRIVATE);
    	int flag = pref.getInt(BDConstents.INSERT_TAB_SELECT_FLAG, 0);
    	
    	tabHost.setCurrentTab(flag);
	}
	
	@Override
	protected void onDestroy()
	{
		super.onDestroy();
		SharedPreferences pref = getSharedPreferences("pref", Activity.MODE_PRIVATE);
		SharedPreferences.Editor editor = pref.edit();
		
		int flag = tabHost.getCurrentTab();
		
		editor.putInt(BDConstents.INSERT_TAB_SELECT_FLAG, flag);
		
		editor.commit();
	}

	@Override
	protected void tipButton()
	{
		Intent intent = new Intent(this, TipInfoActivity.class);
		intent.putExtra(TipsActivity.TIP_REQUEST_KEY, TipsActivity.TIP_INSERT);
		startActivity(intent);
	}
}
